package com.ruoyi.wgjlcData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wgjlcData.domain.plat.DataWgjlcZdqyl;
import com.ruoyi.wgjlcData.domain.vo.TestOneData;
import com.ruoyi.wgjlcData.mapper.DataWgjlcZdqylMapper;
import com.ruoyi.wgjlcData.service.IDataWgjlcZdqylService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;


/**
 * 无轨胶轮车最大牵引力测试项Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-27
 */
@Service
public class DataWgjlcZdqylServiceImpl implements IDataWgjlcZdqylService
{
    @Autowired
    private DataWgjlcZdqylMapper dataWgjlcZdqylMapper;

    /**
     * 查询无轨胶轮车最大牵引力测试项
     * 
     * @param zdqylId 无轨胶轮车最大牵引力测试项主键
     * @return 无轨胶轮车最大牵引力测试项
     */
    @Override
    public DataWgjlcZdqyl selectDataWgjlcZdqylByZdqylId(Long zdqylId)
    {
        return dataWgjlcZdqylMapper.selectDataWgjlcZdqylByZdqylId(zdqylId);
    }

    /**
     * 查询无轨胶轮车最大牵引力测试项列表
     * 
     * @param dataWgjlcZdqyl 无轨胶轮车最大牵引力测试项
     * @return 无轨胶轮车最大牵引力测试项
     */
    @Override
    public List<DataWgjlcZdqyl> selectDataWgjlcZdqylList(DataWgjlcZdqyl dataWgjlcZdqyl)
    {
        return dataWgjlcZdqylMapper.selectDataWgjlcZdqylList(dataWgjlcZdqyl);
    }

    /**
     * 新增无轨胶轮车最大牵引力测试项
     * 
     * @param dataWgjlcZdqyl 无轨胶轮车最大牵引力测试项
     * @return 结果
     */
    @Override
    public int insertDataWgjlcZdqyl(DataWgjlcZdqyl dataWgjlcZdqyl)
    {
        dataWgjlcZdqyl.setCreateTime(DateUtils.getNowDate());
        return dataWgjlcZdqylMapper.insertDataWgjlcZdqyl(dataWgjlcZdqyl);
    }

    /**
     * 修改无轨胶轮车最大牵引力测试项
     * 
     * @param dataWgjlcZdqyl 无轨胶轮车最大牵引力测试项
     * @return 结果
     */
    @Override
    public int updateDataWgjlcZdqyl(DataWgjlcZdqyl dataWgjlcZdqyl)
    {
        dataWgjlcZdqyl.setUpdateTime(DateUtils.getNowDate());
        //list转Json字符串
        if(!dataWgjlcZdqyl.getTestOneDataList().isEmpty()) {
            dataWgjlcZdqyl.setDataList(JSON.toJSONString(dataWgjlcZdqyl.getTestOneDataList()));
        }
        return dataWgjlcZdqylMapper.updateDataWgjlcZdqyl(dataWgjlcZdqyl);
    }

    /**
     * 查询无轨胶轮车-最大牵引力测试项
     *
     * @param dataTaskId
     * @return 无轨胶轮车-最大牵引力测试项
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataWgjlcZdqyl>> selectDataWgjlcZdqylByDataTaskId(Long dataTaskId) {
        List<DataWgjlcZdqyl> dataWgjlcZdqylEntities = dataWgjlcZdqylMapper.selectDataWgjlcZdqylByDataTaskId(dataTaskId);
        if (dataWgjlcZdqylEntities.size() != 0) {
            dataWgjlcZdqylEntities.forEach(item -> {
                if (item.getDataList() != null && item.getDataList().length() != 0) {
                    item.setTestOneDataList(JSON.parseArray(item.getDataList(), TestOneData.class));
                    item.setListSize(item.getTestOneDataList().size());
                }
            });
        }
        return new AsyncResult<>(dataWgjlcZdqylEntities);
    }

    /**
     * 修改状态为2
     *
     * @param dataTaskId
     */
    @Override
    public int updateDataWgjlcZdqylByDataTaskId(Long dataTaskId) {
        return dataWgjlcZdqylMapper.updateDataWgjlcZdqylByDataTaskId(dataTaskId);
    }

    /**
     * 批量新增无轨胶轮车-最大牵引力测试项
     *
     * @param dataWgjlcZdqyl 无轨胶轮车-最大牵引力测试项
     * @return 结果
     */
    @Override
    public int batchDataWgjlcZdqyl(List<DataWgjlcZdqyl> dataWgjlcZdqyl) {
        return dataWgjlcZdqylMapper.batchDataWgjlcZdqyl(dataWgjlcZdqyl);
    }

    /**
     * 批量删除无轨胶轮车最大牵引力测试项
     * 
     * @param zdqylIds 需要删除的无轨胶轮车最大牵引力测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcZdqylByZdqylIds(Long[] zdqylIds)
    {
        return dataWgjlcZdqylMapper.deleteDataWgjlcZdqylByZdqylIds(zdqylIds);
    }

    /**
     * 删除无轨胶轮车最大牵引力测试项信息
     * 
     * @param zdqylId 无轨胶轮车最大牵引力测试项主键
     * @return 结果
     */
    @Override
    public int deleteDataWgjlcZdqylByZdqylId(Long zdqylId)
    {
        return dataWgjlcZdqylMapper.deleteDataWgjlcZdqylByZdqylId(zdqylId);
    }
}
